/* $Id$ */
package org.crazydays.gameplan.map.swing;


import java.awt.Component;
import java.awt.event.MouseEvent;

import org.junit.*;
import static org.junit.Assert.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.Actions;
import org.crazydays.gameplan.Controller;

/**
 * MapFrameMouseListenerUnitTest
 */
public class MapMouseListenerUnitTest
{
    /**
     * Test constructor.
     */
    @Test
    public void testConstructor()
    {
        // mocks
        Controller controller = createMock(Controller.class);

        // objects
        Actions actions = new Actions(controller);

        // expect
        expect(controller.getActions()).andReturn(actions).anyTimes();

        // replay
        replay(controller);

        // test
        MapMouseListener listener = new MapMouseListener(controller);

        // verify
        verify(controller);

        assertEquals("controller", controller, listener.controller);
        assertNotNull("menu", listener.menu);
    }

    /**
     * Test released(MouseEvent).
     */
    @Test
    public void testMouseReleased()
    {
        // mocks
        Controller controller = createMock(Controller.class);
        JMapContextMenu menu = createMock(JMapContextMenu.class);
        MouseEvent event = createMock(MouseEvent.class);
        Component component = createMock(Component.class);

        // objects
        Actions actions = new Actions(controller);

        // expect
        expect(controller.getActions()).andReturn(actions).anyTimes();
        expect(event.getButton()).andReturn(MouseEvent.BUTTON3);
        expect(event.getComponent()).andReturn(component);
        expect(event.getX()).andReturn(42);
        expect(event.getY()).andReturn(24);
        menu.show(component, 42, 24);

        // replay
        replay(controller, menu, event, component);

        // setup
        MapMouseListener listener = new MapMouseListener(controller);
        listener.menu = menu;

        // test
        listener.mouseReleased(event);

        // verify
        verify(controller, menu, event, component);
    }
}
